/*
 * Copyright (C) 2014 Will Dignazio
 * config.c
 */

#include "internal.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <libconfig.h>

int
conf_load(const char *cfpath, Error *err)
{
	config_t conf;
	struct stat buffer;
	int ret;

	ret = stat(cfpath, &buffer);
	if(ret !=0) { // File does not exist
		error(err, "Configuration file %s does not exist.\n", cfpath);
		goto err;
	}

	config_init(&conf);
	ret = config_read_file(&conf, cfpath);
	if(ret != CONFIG_TRUE) {
		error(err, "Configuration file failed to parse: %s\n", config_error_text(&conf));
		goto err;
	}

	ret = 0;
err:
	return ret;
}
